﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.Guild"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>길드 관리(마스터/부마스터 전용)</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<%
DAO dao = DAO.getInstance();
int charNo = (Integer)session.getAttribute("charNo");
Guild.GuildMember member = dao.getGuildMember(charNo);
Guild guild;
Guild.GuildMember[] listMembers;
//마스터나 부마스터인 경우에만
if( member != null && 
	( member.getJob_name().compareTo(Guild.GuildMember.MEMBER_MASTER) == 0 ||
	member.getJob_name().compareTo(Guild.GuildMember.MEMBER_VICEMASTER) == 0 ) ){
	guild = dao.getGuild(member.getGuild_no());
	listMembers = dao.getGuildMemberListInGuild(guild.getNo());
	
	//부관리자 저장
	Guild.GuildMember[] viceMasters = new Guild.GuildMember[2];
	int viceCnt = 0;
	for( Guild.GuildMember mem : listMembers ){
		if( mem.getJob_name().compareTo(Guild.GuildMember.MEMBER_VICEMASTER) == 0){
			viceMasters[viceCnt++] = mem;
		}
	}
%>
<form name="form1" method="post" action="../post/postManageGuild.jsp">
    <h1>길드관리하기</h1>
    <table border="1" cellspacing="0" bordercolordark="white" bordercolorlight="black">
        <tr>
            <td width="191"><span style="font-size:9pt;">길드이름</span></td>
            <td width="509"><span style="font-size:9pt;"><%=guild.getName() %></span></td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드포인트</span></td>
            <td width="509"><span style="font-size:9pt;"><%=guild.getPoint() %>/<%=guild.getGrade().getLimit_point() %></span></td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드회원수</span></td>
            <td width="509"><span style="font-size:9pt;"><%=guild.getMember_cnt() %>/<%=guild.getGrade().getLimit_member_cnt() %></span></td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드등급</span></td>
            <td width="509"><span style="font-size:9pt;"><%=guild.getGrade().getName() %></span></td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드 경험치 혜택</span></td>
            <td width="509"><span style="font-size:9pt;"><%=guild.getGrade().getBenefit_exp() %></span></td>
        </tr>
        
        <% if( viceMasters.length > 0){%>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드 부 관리자</span></td>
            <td width="509"><span style="font-size:9pt;">
            <%if( viceMasters[0] != null ) {%>
            	<input type="hidden" name="exViceCharNo1" value="<%=viceMasters[0].getChar_no()%>">
            	<%out.println(viceMasters[0].getChar_name()); 
            }%>
            </span></td>
        </tr>	
        <%}
        if( viceMasters.length > 1){%>
       	<tr>
            <td width="191"><span style="font-size:9pt;">&nbsp;</span></td>
            <td width="509"><span style="font-size:9pt;">
            <%if( viceMasters[1] != null ) {%>
            	<input type="hidden" name="exViceCharNo2" value="<%=viceMasters[1].getChar_no()%>">
            	<%out.println(viceMasters[1].getChar_name()); 
            }%>
            </span></td>
        </tr>
        <%} %>
        
        
        
        <!-- 길드 직책이 마스터인 사람만 부마스터 지정할 수 있게. -->
        <%if( member.getJob_name().compareTo(Guild.GuildMember.MEMBER_MASTER) == 0 ){%>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드 부 관리자 선택</span></td>
            <td width="509"><span style="font-size:9pt;">
            	<select name="viceCharNo1" size="1">
            		<%for( int i = 0; i < listMembers.length; i++ ){ 
            			if(listMembers[i].getJob_name().compareTo(Guild.GuildMember.MEMBER_WAITING) != 0 ){%>
                    		<option value=<%=listMembers[i].getChar_no() %>><%=listMembers[i].getChar_name() %></option>
                    	<%} %>
                    <%} %>
				</select></span>
			</td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;">&nbsp;</span></td>
            <td width="509"><span style="font-size:9pt;">
            	<select name="viceCharNo2" size="1">
                    <%for( int i = 0; i < listMembers.length; i++ ){ 
            			if(listMembers[i].getJob_name().compareTo(Guild.GuildMember.MEMBER_WAITING) != 0 ){%>
                    		<option value=<%=listMembers[i].getChar_no() %>><%=listMembers[i].getChar_name() %></option>
                    	<%} %>
                    <%} %>
				</select></span>
			</td>
        </tr>
        <%} %>
        <tr>
            <td width="191"><span style="font-size:9pt;">길드가입대기자</span></td>
            <td width="509"><span style="font-size:9pt;">
            	<select name="guildWaitingCharNo" size="1">
            		<%for( int i = 0; i < listMembers.length; i++ ){ 
            			if(listMembers[i].getJob_name().compareTo(Guild.GuildMember.MEMBER_WAITING) == 0 ){%>
                    		<option value=<%=listMembers[i].getChar_no() %>><%=listMembers[i].getChar_name() %></option>
                    	<%} %>
                    <%} %>
				</select></span>
			</td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;">&nbsp;</span></td>
            <td width="509"><span style="font-size:9pt;">&nbsp;</span></td>
        </tr>
        <tr>
            <td width="191"><span style="font-size:9pt;"><input type="submit" name="action" value="참가승인"></span></td>
            <%if( member.getJob_name().compareTo(Guild.GuildMember.MEMBER_MASTER) == 0 ){%><td width="509"><span style="font-size:9pt;"><input type="submit" name="action" value="부마스터 변경"></span></td><%} %>
        </tr>
    </table>
</form>
<p>&nbsp;</p>

<%}
else if(member != null){
	out.println("길드관리 권한이 없습니다.<br> 회원님의 길드 직책은 현재 " + member.getJob_name() + "이십니다.");
}
else{
	out.println("길드 가입이 되어있지 않습니다. 길드 가입부터 하세요.");
}%>
</body>

</html>